#ifndef __TIMER_H__
#define __TIMER_H__

#include <functional>
#include <chrono>
#include <memory>

using TimerCallback = std::function<void()>;

class Timer
{
public:
    Timer(int64_t timerId, 
          std::chrono::steady_clock::time_point expireTime,
          std::chrono::milliseconds interval,
          TimerCallback &&callback);
    
    ~Timer() = default;
    
    int64_t getTimerId() const { return _timerId; }
    std::chrono::steady_clock::time_point getExpireTime() const { return _expireTime; }
    std::chrono::milliseconds getInterval() const { return _interval; }
    bool isRepeated() const { return _interval.count() > 0; }
    
    void run();
    void restart();
    
private:
    int64_t _timerId;
    std::chrono::steady_clock::time_point _expireTime;
    std::chrono::milliseconds _interval;
    TimerCallback _callback;
};

using TimerPtr = std::shared_ptr<Timer>;

#endif